package com.dhh.vo;

import java.util.ArrayList;
import java.util.List;

public class FoodDiet {
	public static final String C_ID = "_id";
	public static final String C_DATE = "date";
	public static final String C_NAME = "name";
	public static final String C_PLAN = "plan_id";
	
	private String id;
	private String date;
	private String name;
	private String planId;

	private List<PlanItem> breakFast;
	private List<PlanItem> lunch;
	private List<PlanItem> dinner;
	private List<PlanItem> snack;	
	
	private Long cGrain = 0l;
	private Long cFruit = 0l;
	private Long cVegetable = 0l;
	private Long cDairy = 0l;
	private Long cProtein = 0l;
	
	public FoodDiet(){}
	
	public FoodDiet(String id,String date,String name,String planId){
		this.id = id;
		this.date =date;
		this.name = name;
		this.planId = planId;
	}
	
	public String getCurrentGrain() {
		return String.valueOf(cGrain);
	}

	public String getCurrentFruit() {
		return String.valueOf(cFruit);
	}

	public String getCurrentVegetable() {
		return String.valueOf(cVegetable);
	}

	public String getCurrentDairy() {
		return String.valueOf(cDairy);
	}

	public String getCurrentProteinFood() {
		return String.valueOf(cProtein);
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPlanId() {
		return planId;
	}

	public void setPlanId(String planId) {
		this.planId = planId;
	}

	
	public void initCurentCount(){
		List<PlanItem> items = new ArrayList<PlanItem>();
		items.addAll(breakFast);
		items.addAll(lunch);
		items.addAll(dinner);
		items.addAll(snack);
		
		for(PlanItem item : items){
			if(Food.FOOD_GROUP_GRAIN.equals(item.getFoodGroup())){
				cGrain += Long.parseLong(item.getQuatity());
			}else if(Food.FOOD_GROUP_FRUIT.equals(item.getFoodGroup())){
				cFruit += Long.parseLong(item.getQuatity());	
			}else if(Food.FOOD_GROUP_VEGETABLE.equals(item.getFoodGroup())){
				cVegetable += Long.parseLong(item.getQuatity());	
			}else if(Food.FOOD_GROUP_PROTEIN.equals(item.getFoodGroup())){
				cProtein += Long.parseLong(item.getQuatity());		
			}else if(Food.FOOD_GROUP_DAIRY.equals(item.getFoodGroup())){
				cDairy += Long.parseLong(item.getQuatity());
			}				
		}
	}
	
	public String getCurrentEnergy(){
		List<PlanItem> items = new ArrayList<PlanItem>();
		items.addAll(breakFast);
		items.addAll(lunch);
		items.addAll(dinner);
		items.addAll(snack);
		
		int count = 0;
		for(PlanItem item : items){
			if(item.getEnergy()!=null){
				count += Integer.parseInt(item.getEnergy());
			}
		}
		
		return String.valueOf(count);
	}
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getDate() {
		return date;
	}
	public void setDate(String date) {
		this.date = date;
	}
	public List<PlanItem> getBreakFast() {
		return breakFast;
	}
	public void setBreakFast(List<PlanItem> breakFast) {
		this.breakFast = breakFast;
	}
	public List<PlanItem> getLunch() {
		return lunch;
	}
	public void setLunch(List<PlanItem> lunch) {
		this.lunch = lunch;
	}
	public List<PlanItem> getDinner() {
		return dinner;
	}
	public void setDinner(List<PlanItem> dinner) {
		this.dinner = dinner;
	}
	public List<PlanItem> getSnack() {
		return snack;
	}
	public void setSnack(List<PlanItem> snack) {
		this.snack = snack;
	}	
	
	public static String[] getColumns(){
		return new String[]{C_ID,C_DATE,C_NAME,C_PLAN};
	}
}
